//
//  SelectPublicView.m
//  Shengzhuli
//
//  Created by FXGuo on 2017/5/16.
//  Copyright © 2017年 kamangkeji. All rights reserved.
//

#import "SelectPublicView.h"

@interface SelectPublicView ()

@property (weak, nonatomic) IBOutlet UIButton *adderBtn;
@property (weak, nonatomic) IBOutlet UIButton *experienceBtn;


@end

@implementation SelectPublicView

+ (instancetype)selectPublicView
{
    return [[[NSBundle mainBundle]loadNibNamed:NSStringFromClass([SelectPublicView class]) owner:nil options:nil]lastObject];
}

- (IBAction)btnClick:(UIButton *)btn
{
    if (btn.tag == 0 ||btn.tag == 1) {
        btn.selected = !btn.selected;
        if (btn.selected) {
            btn.backgroundColor = RGBColor(254, 204, 204);
        }else {
            btn.backgroundColor = RGBColorOne(242);
        }
    }else if (btn.tag == 2) {
        self.adderBtn.selected = NO;
        self.adderBtn.backgroundColor = RGBColorOne(242);
        self.experienceBtn.selected = NO;
        self.experienceBtn.backgroundColor = RGBColorOne(242);
    }else if (btn.tag == 3) {
        NSInteger ID = 0;
        if (self.adderBtn.selected&&self.experienceBtn.selected) {
            ID = 0;
        }else if (!self.adderBtn.selected&&!self.experienceBtn.selected){
            ID = 0;
        }else if (self.adderBtn.selected&&!self.experienceBtn.selected){
            ID = 2;
        }else if (!self.adderBtn.selected&&self.experienceBtn.selected){
            ID = 3;
        }
        if ([self.delegate respondsToSelector:@selector(selectPublicViewClick:)]) {
            [self.delegate selectPublicViewClick:ID];
        }
        [self dismiss];
    }else {
        [self dismiss];
    }
}
- (void)createPublicView
{
    if (!self.superview) {
        [[[UIApplication sharedApplication] keyWindow] addSubview:self];
        self.alpha = 0.0f;
        [UIView animateWithDuration:0.2f animations:^{
            self.alpha = 1.0f;
        }];
        [UIView animateWithDuration:0.2f animations:^{
            if (self.arrowView) {
                self.arrowView.transform = CGAffineTransformMakeRotation(M_PI);
            }
        }];
    }else {
        [self dismiss];
    }
}
- (void)dismiss{
    
    if(self.superview) {
        [self removeFromSuperview];
        [UIView animateWithDuration:0.2 animations:^{
            if (self.arrowView) {
                self.arrowView.transform = CGAffineTransformMakeRotation(0);
            }
        }];
        
    }
}



@end
